import { spotHttp } from '@/utils/http';

const mockSpots = [
  {
    id: 1,
    name: '故宫博物院',
    image: require('@/assets/images/gugong.jpg'),
    description: '北京故宫是中国明清两代的皇家宫殿，旧称紫禁城，位于北京中轴线的中心。',
    address: '北京市东城区景山前街4号',
    rating: 4.8,
    openingTime: '08:30-17:00',
    price: '旺季 60元，淡季 40元',
    tags: ['历史古迹', '文化', '亲子游'],
    comments: [
      { user: '游客A', content: '非常宏伟，不虚此行！' },
      { user: '游客B', content: '历史的厚重感扑面而来。' }
    ]
  },
  {
    id: 2,
    name: '西湖',
    image: require('@/assets/images/xihu.jpg'),
    description: '杭州西湖以其秀丽的湖光山色和众多的名胜古迹而闻名中外，被誉为"人间天堂"。',
    address: '浙江省杭州市西湖区',
    rating: 4.9,
    openingTime: '全天开放',
    price: '免费',
    tags: ['自然风光', '情侣游', '徒步'],
    comments: [
        { user: '游客C', content: '风景如画，美不胜收。' },
    ]
  },
  {
    id: 3,
    name: '张家界国家森林公园',
    image: require('@/assets/images/zhangjiajie.jpg'),
    description: '中国第一个国家森林公园，以其独特的石英砂岩峰林地貌和壮丽的自然景观著称。',
    address: '湖南省张家界市',
    rating: 4.7,
    openingTime: '07:00-18:00',
    price: '228元',
    tags: ['自然风光', '探险', '徒步'],
    comments: []
  }
];

// 模拟获取所有景点
// 修改 API 调用方法（如果后续需要调用真实接口）
export const getSpots = (params = {}) => {
  // 如果需要调用真实接口，可以使用：
  // return spotHttp.get('/spots', { params });
  
  // 当前使用 mock 数据的代码保持不变
  return new Promise((resolve) => {
    setTimeout(() => {
      let spots = [...mockSpots];
      if (params.name) {
        spots = spots.filter(s => s.name.includes(params.name));
      }
      if (params.region) {
        spots = spots.filter(s => s.address.includes(params.region));
      }
      if (params.tag) {
        spots = spots.filter(s => s.tags.includes(params.tag));
      }
      resolve({ data: spots });
    }, 500);
  });
};

// 模拟根据ID获取景点详情
export const getSpotById = (id) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const spot = mockSpots.find(s => s.id === parseInt(id));
      resolve({ data: spot });
    }, 300);
  });
};

// 获取路线规划
export const getRoute = (origin, destination) => {
  return spotHttp.get('/api/map/route', {
    params: { origin, destination }
  });
};